
const pdfFileType = {
  "xls": "xls",
  "xlsx": "xlsx",
    "doc": "doc",
    "docx": "docx",
    "pdf":"pdf"
};
const imgFileType = {
    "jpg": "jpg",
    "jpeg": "jpeg",
    "bmp": "bmp",
    "png": "png",
    "gif": "gif",
};
    //"xls": "application/vnd.ms-excel",
    //"xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    //"doc": "application/msword",
    //"docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
const fileTypeMap = {
    "xls": "application/pdf",
    "xlsx": "application/pdf",
    "doc": "application/pdf",
    "docx": "application/pdf",
    "pdf": "application/pdf",
    "ppt": "application/pdf",
    "pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
    "png": "image/png",
    "gif": "image/gif",
    "jpeg": "image/jpeg",
    "jpg": "image/jpeg",
    "txt": "text/plain",
};
/**
 * 
 * @param {string} filename 
 * @returns {resolve || reject}
 */
function GetFileType(filename) {
  return new Promise((resolve, reject) => {
    var nIndex = filename ? filename.lastIndexOf(".") : -1;
    if (nIndex !== -1) {
      var filetype = filename.substring(nIndex + 1).toLowerCase();
        if (pdfFileType[filetype]) resolve(true);
        if (imgFileType[filetype]) resolve(false);
      reject();
    } else {
      reject();
    }
  });
}
function GetFileMap(filename) {
    return new Promise((resolve, reject) => {
        var nIndex = filename ? filename.lastIndexOf(".") : -1;
        if (nIndex !== -1) {
            var filetype = filename.substring(nIndex + 1).toLowerCase();
            if (fileTypeMap[filetype]) {
                var a = fileTypeMap[filetype];
                resolve(a)
            } ;
            reject();
        } else {
            reject();
        }
    });
}